package com.ruoyi.system.controller;

import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.common.utils.file.FileUtils;
import com.ruoyi.system.constants.CommonConstants;
import com.ruoyi.system.domain.ByExportTask;
import com.ruoyi.system.service.IEsService;
import com.ruoyi.system.task.ByExportThreadTask;
import com.ruoyi.system.utils.MinioUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ByDb15;
import com.ruoyi.system.service.IByDb15Service;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * StandardController
 * 
 * @author ruoyi
 * @date 2024-02-01
 */
@RestController
@RequestMapping("/system/db15")
public class ByDb15Controller extends BaseController
{
    @Autowired
    private IByDb15Service byDb15Service;

    @Autowired
    private IEsService esService;

    /**
     * 查询Standard列表
     */
    @PreAuthorize("@ss.hasPermi('system:db15:list')")
    @GetMapping("/list")
    public TableDataInfo list(ByDb15 byDb15)
    {
        startPage();
        List<ByDb15> list = byDb15Service.selectByDb15List(byDb15);
        return getDataTable(list);
    }

    /**
     * 一筐式检索
     */
    @PreAuthorize("@ss.hasPermi('system:db15:list')")
    @GetMapping("/searchone")
    public TableDataInfo searchone(ByDb15 byDb15)
    {
        return esService.search(byDb15.getA298());
    }

    /**
     * 导出Standard列表
     */
    @PreAuthorize("@ss.hasPermi('system:db15:export')")
    @Log(title = "Standard", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(@RequestBody ByDb15 byDb15)
    {
        esService.export(byDb15);
    }

    /**
     * 导出Standard列表
     */
    @PreAuthorize("@ss.hasPermi('system:db15:export')")
    @Log(title = "Standard", businessType = BusinessType.EXPORT)
    @PostMapping("/exportFile")
    public void exportFile(@RequestBody ByDb15 byDb15)
    {
        esService.exportFile(byDb15);
    }

    /**
     * 获取Standard详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:db15:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(byDb15Service.selectByDb15ById(id));
    }

    /**
     * 新增Standard
     */
    @PreAuthorize("@ss.hasPermi('system:db15:add')")
    @Log(title = "Standard", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ByDb15 byDb15)
    {
        return toAjax(byDb15Service.insertByDb15(byDb15));
    }

    /**
     * 修改Standard
     */
    @PreAuthorize("@ss.hasPermi('system:db15:edit')")
    @Log(title = "Standard", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ByDb15 byDb15)
    {
        return toAjax(byDb15Service.updateByDb15(byDb15));
    }

    /**
     * 删除Standard
     */
    @PreAuthorize("@ss.hasPermi('system:db15:remove')")
    @Log(title = "Standard", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(byDb15Service.deleteByDb15ByIds(ids));
    }


    /**
     * 通用上传请求（单个）
     */
    @PostMapping("/upload")
    public AjaxResult uploadFile(MultipartFile file) throws Exception
    {
        return byDb15Service.upload(file);
    }

    /**
     * 获取Standard详细信息
     */
    @GetMapping(value = "/getCal/{tableName}")
    public AjaxResult getCal(@PathVariable("tableName") String tableName)
    {
        return success(byDb15Service.getCal(tableName));
    }


    /**
     * 获取Standard详细信息
     */
    @GetMapping(value = "/updateCal")
    public AjaxResult updateCal()
    {
        return success(esService.addContentByTableName("standard_no_es"));
    }

}
